<?php


namespace App\Libraries\Express;


use App\Libraries\Express\Driver\YunDa;
use App\Libraries\Express\Driver\Zto;
use App\Models\Order;

/**
 * Class Client
 * @package App\Libraries\Express
 * @method Response create()
 * @method Response update()
 * @method bool customs()
 * @method string getPdf()
 *
 * @see Express
 */
class Client
{
    /**
     * @var Express
     */
    protected $driver;

    /**
     * Client constructor.
     * @param $model
     */
    public function __construct(Order $model)
    {
        switch ($model->express->getAttribute('code')) {
            case 'ZTOCS':
                $this->driver = new Zto($model);
                break;
            case 'YUNDA':
                $this->driver = new YunDa($model);
        }
    }

    /**
     * @param $name
     * @param $arguments
     * @return mixed
     */
    public function __call($name, $arguments)
    {
        if (method_exists($this->driver, $name)) {
            return call_user_func_array([$this->driver, $name], $arguments);
        }
    }
}
